<template>
  <div class="pr h100">
<!--     
    <span class="red dfdrttee">最大振幅{{zf}}%</span> -->
    <div class="echarDx" ref="echarDxers" :data-currentTime='currentTime'></div>
  </div>
</template>
<script lang='ts' setup>
  import { ref,computed } from "vue";
  import store from "../../store";
  import { dxget, qurl } from "../../util/index";
  import ecahrData from "../../util/ecahrData";
  import stock from "../../store/stock";
  let charDada = new ecahrData();
  const echarDxers = ref()
  const zf = ref()
  let props = defineProps({
    code: { type: String },
  })
  const initData = async (ty)=>{
      let res: any = await dxget("czsc/index", {
        code: props.code,
      });
      let option = charDada.setDateLine(res.data.klines,ty);
      var myChart = window.echarts.init(echarDxers.value);
      if(ty){
        let seriesData = []
        res.data.klines.map(a => {
          seriesData.push([a[1], a[2], a[4], a[3], a[5], a[7], a[8], a[9]])
        })
        let inf:any = stock.state.gpinfo
        
        let jhjkswe = Math.ceil(Math.random()*30);
        seriesData[seriesData.length-1][1]  = inf.f43
    
        myChart.setOption({
          series: [{
              data: seriesData
          }]
      });
      }else{
        myChart.setOption(option);
      }
    }
    initData(false);

  const currentTime = computed(() => {
      const newDate = new Date();
      const Hours = newDate.getHours();
      const myddy = newDate.getDay(); //获取存储当前日期
      /*每天的15点以后 和9点前 周六和周天 不刷新 */
      console.log(myddy);
      if (Hours > 15 || Hours < 8 || myddy == 6 || myddy == 0) {
        return;
      }
      // initData(true);
      return store.state.currentTime;
    });


</script>
<style scoped>

</style>